# middleware.py

class RequestLoggingMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        # 在请求到达服务器前记录请求信息
        print(f"Received {request.method} request to {request.path} with data: {request.body}")

        response = self.get_response(request)

        # 在响应返回给客户端后，如果需要的话，也可以记录响应信息
        print(f"Sent {response.status_code} response with data: {response.content.decode('utf-8')}")

        return response
